package wrs.hcs.functions;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import jxl.read.biff.BiffException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class WebApp_Pair {

	public void wellness(WebDriver driver, String pin1, String pin2, String lName1, String lName2, boolean guarantor) throws BiffException, IOException{
		
		//Go to wellness reservation
		Miscellaneous m = new Miscellaneous();
		m.goto_wellness_webapp(driver);
		Web_App app = new Web_App();
		app.step_1(driver, "GC", "Pair");
		app.step_2_pair(driver, pin1, pin2, lName1, lName2);
		app.step_3_pair(driver, "basic", "overweight", "private");
		String email_address = m.get_xls_details();
		String finalDateInput = m.set_date_webapp();
		app.step_4_pair(driver, email_address, finalDateInput, guarantor);
		app.step_5(driver);
		app.step_payment(driver, "mastercard");
		
		System.out.println("Pair Transaction Completed!");
	}
	
	public void new_date(WebDriver driver, String date){
		String strYear="";
		boolean my_date = false;
		String new_date[] = date.split("/"); 			//split date
		int intDay = Integer.parseInt(new_date[1]);
		int intMonth = Integer.parseInt(new_date[0]);
		do{
			intDay++;
			if(intDay>=30){
				intMonth++;
				intDay=1;
			}
			if(intMonth>12){
				int intYear = Integer.parseInt(new_date[2]);
				strYear = Integer.toString(intYear);
			}
			String strDay = Integer.toString(intDay);
			String strMonth = Integer.toString(intMonth);
			String finalDate = strMonth+"/"+strDay+"/"+strYear;
			driver.findElement(By.xpath("//input[@id='datepicker2']")).sendKeys(finalDate);
			driver.findElement(By.xpath("//button[@class='btn btn-primary']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
			if(driver.findElement(By.xpath("//p[@id='errorMessage']/p")).getText().equals("Plan Admission Date must be a week greater than date today.")){
				driver.findElement(By.xpath("//input[@id='errorPopupClose']")).click();
				driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			}
			
		}while(my_date==false);
		
	}
	
}
